<?php
class PageAction extends HomeBaseAction{

	public function index() {
		if(I('get.location')){
			$this->location = I('get.location');
		}else{
			$this->location = I('get.id');
		}

        C('OUTPUT_ENCODE',false);
        
        if(!$_GET['id']){
            echo '404 Not Found!';exit;
        }
        
        $id = I('get.id');

        $article = M('posts')->where('id='.$id)->find();
        // p($article);

        if(empty($article)){
            echo '404 Not Found !';exit;
        }

        //存在 阅读view+1
        M('posts')->where('id='.$id)->setInc('view');

        // 单页的 模板在smeta 里面
		$article['smeta'] = json_decode($article['smeta'],true);

		$tpl = $smeta['template']?$smeta['template']:"page";
		
		$this->article = $article;
		
		$this->assign($article);
		$this->display(":$tpl");
	}
	
	public function nav_index(){
		$navcatname="页面";
		$datas=sp_sql_pages("field:ID,post_title;");
		$navrule=array(
				"action"=>"Page/index",
				"param"=>array(
						"id"=>"ID"
				),
				"label"=>"post_title");
		echo sp_get_nav4admin($navcatname,$datas,$navrule);
	}
}